package com.wltt.healing.healinguserservice.service.impl;

import com.wltt.healing.healinguserservice.service.BaseService;
import org.reactivestreams.Publisher;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.Serializable;


/**
 * @Author: wltt
 * @Date: 2021/9/8 15:26：
 * @Version: 1.0
 * @Description: TODO
 */
public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID> {

    ReactiveCrudRepository<T, ID> baseRepository;

    //构造方法
    public BaseServiceImpl(ReactiveCrudRepository<T, ID> baseRepository) {
        this.baseRepository = baseRepository;
    }


    @Override
    public <S extends T> Mono<S> save(S entity) {
        return baseRepository.save(entity);
    }

    @Override
    public <S extends T> Flux<S> saveAll(Iterable<S> entities) {
        return baseRepository.saveAll(entities);
    }

    @Override
    public <S extends T> Flux<S> saveAll(Publisher<S> entityStream) {
        return baseRepository.saveAll(entityStream);
    }

    @Override
    public Mono<T> findById(ID id) {
        return baseRepository.findById(id);
    }

    @Override
    public Mono<T> findById(Publisher<ID> id) {
        return baseRepository.findById(id);
    }

    @Override
    public Mono<Boolean> existsById(ID id) {
        return baseRepository.existsById(id);
    }

    @Override
    public Mono<Boolean> existsById(Publisher<ID> id) {
        return baseRepository.existsById(id);
    }

    @Override
    public Flux<T> findAll() {
        return baseRepository.findAll();
    }

    @Override
    public Flux<T> findAllById(Iterable<ID> ids) {
        return baseRepository.findAllById(ids);
    }

    @Override
    public Flux<T> findAllById(Publisher<ID> idStream) {
        return baseRepository.findAllById(idStream);
    }

    @Override
    public Mono<Long> count() {
        return baseRepository.count();
    }

    @Override
    public Mono<Void> deleteById(ID id) {
        return baseRepository.deleteById(id);
    }

    @Override
    public Mono<Void> deleteById(Publisher<ID> id) {
        return baseRepository.deleteById(id);
    }

    @Override
    public Mono<Void> delete(T entity) {
        return baseRepository.delete(entity);
    }

    @Override
    public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
        return baseRepository.deleteAllById(ids);
    }

    @Override
    public Mono<Void> deleteAll(Iterable<? extends T> entities) {
        return baseRepository.deleteAll(entities);
    }

    @Override
    public Mono<Void> deleteAll(Publisher<? extends T> entityStream) {
        return baseRepository.deleteAll(entityStream);
    }

    @Override
    public Mono<Void> deleteAll() {
        return baseRepository.deleteAll();
    }
}